import cv2
import mediapipe as mp
import time
import numpy as np
def dis(lmHands):
    return np.sqrt((lmHands[8][1]-lmHands[8][1])**2+ (lmHands[8][2] - lmHands[12][2])**2)

img = cv2.imread("img/hand_img.jpg")
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils

imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)

lmList = []

if results.multi_hand_landmarks:
    for handLms in results.multi_hand_landmarks:
        print(handLms.landmark)
        for id, lm in enumerate(handLms.landmark):
            h,w,c = img.shape
            print("h,w,c: ",h,w,c)
            print("x,y: ",lm.x,lm.y)
            cx,cy = int(lm.x * w), int(lm.y * h)
            print(id, cx, cy)
            lmList.append([id,cx,cy])
            #cv2.circle(img, (cx,cy), int(w/50),(255,0,255),cv2.FILLED)
        mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
print(lmList)
print(lmList[3][1])
print(dis(lmList))
cv2.imshow("img",img)
cv2.waitKey()
cv2.destroyAllWindows()
